home *** CD-ROM | disk | FTP | other *** search
/ Motor Sport Digital Archive Collection 1960s / Motor Sport Digital Archive Collection 1960s.iso / main.swf / scripts / mx / effects / EffectManager.as < prev    next >
Encoding:
Text File  |  2008-05-21  |  18.3 KB  |  573 lines

  1. package mx.effects
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.display.DisplayObjectContainer;
  5.    import flash.events.Event;
  6.    import flash.events.EventDispatcher;
  7.    import flash.events.FocusEvent;
  8.    import flash.system.ApplicationDomain;
  9.    import mx.core.Application;
  10.    import mx.core.EventPriority;
  11.    import mx.core.IDeferredInstantiationUIComponent;
  12.    import mx.core.IFlexDisplayObject;
  13.    import mx.core.IUIComponent;
  14.    import mx.core.UIComponent;
  15.    import mx.core.UIComponentCachePolicy;
  16.    import mx.core.mx_internal;
  17.    import mx.events.EffectEvent;
  18.    import mx.events.FlexEvent;
  19.    import mx.events.MoveEvent;
  20.    import mx.events.ResizeEvent;
  21.    import mx.resources.ResourceBundle;
  22.    
  23.    use namespace mx_internal;
  24.    
  25.    public class EffectManager extends EventDispatcher
  26.    {
  27.       private static var resourceIncorrectTrigger:String;
  28.       
  29.       mx_internal static var lastEffectCreated:Effect;
  30.       
  31.       mx_internal static const VERSION:String = "2.0.1.0";
  32.       
  33.       private static var packageResources:ResourceBundle = ResourceBundle.getResourceBundle("effects",ApplicationDomain.currentDomain);
  34.       
  35.       mx_internal static var effectsPlaying:Array = [];
  36.       
  37.       private static var effectTriggersForEvent:Object = {};
  38.       
  39.       private static var eventsForEffectTriggers:Object = {};
  40.       
  41.       private static var targetsInfo:Array = [];
  42.       
  43.       private static var eventHandlingSuspendCount:Number = 0;
  44.       
  45.       loadResources();
  46.       
  47.       public function EffectManager()
  48.       {
  49.          super();
  50.       }
  51.       
  52.       private static function createAndPlayEffect(param1:Event, param2:Object) : void
  53.       {
  54.          var _loc3_:Effect = null;
  55.          var _loc4_:int = 0;
  56.          var _loc5_:int = 0;
  57.          var _loc6_:int = 0;
  58.          var _loc7_:int = 0;
  59.          var _loc8_:Array = null;
  60.          var _loc9_:String = null;
  61.          var _loc10_:Array = null;
  62.          var _loc11_:Array = null;
  63.          var _loc12_:Array = null;
  64.          var _loc13_:Array = null;
  65.          var _loc14_:EffectInstance = null;
  66.          _loc3_ = mx_internal::createEffectForType(param2,param1.type);
  67.          if(!_loc3_)
  68.          {
  69.             return;
  70.          }
  71.          if(_loc3_ is Zoom && param1.type == MoveEvent.MOVE)
  72.          {
  73.             throw new Error(resourceIncorrectTrigger);
  74.          }
  75.          if(param2.initialized == false)
  76.          {
  77.             _loc9_ = param1.type;
  78.             if(_loc9_ == MoveEvent.MOVE || _loc9_ == ResizeEvent.RESIZE || _loc9_ == FlexEvent.SHOW || _loc9_ == FlexEvent.HIDE || _loc9_ == Event.CHANGE)
  79.             {
  80.                _loc3_ = null;
  81.                return;
  82.             }
  83.          }
  84.          if(_loc3_.target is IUIComponent)
  85.          {
  86.             _loc10_ = IUIComponent(_loc3_.target).tweeningProperties;
  87.             if((Boolean(_loc10_)) && _loc10_.length > 0)
  88.             {
  89.                _loc11_ = _loc3_.getAffectedProperties();
  90.                _loc4_ = int(_loc10_.length);
  91.                _loc6_ = int(_loc11_.length);
  92.                _loc5_ = 0;
  93.                while(_loc5_ < _loc4_)
  94.                {
  95.                   _loc7_ = 0;
  96.                   while(_loc7_ < _loc6_)
  97.                   {
  98.                      if(_loc10_[_loc5_] == _loc11_[_loc7_])
  99.                      {
  100.                         _loc3_ = null;
  101.                         return;
  102.                      }
  103.                      _loc7_++;
  104.                   }
  105.                   _loc5_++;
  106.                }
  107.             }
  108.          }
  109.          if(_loc3_.target is UIComponent && UIComponent(_loc3_.target).mx_internal::isEffectStarted)
  110.          {
  111.             _loc12_ = _loc3_.getAffectedProperties();
  112.             _loc5_ = 0;
  113.             while(_loc5_ < _loc12_.length)
  114.             {
  115.                _loc13_ = _loc3_.target.mx_internal::getEffectsForProperty(_loc12_[_loc5_]);
  116.                if(_loc13_.length > 0)
  117.                {
  118.                   if(param1.type == ResizeEvent.RESIZE)
  119.                   {
  120.                      return;
  121.                   }
  122.                   _loc7_ = 0;
  123.                   while(_loc7_ < _loc13_.length)
  124.                   {
  125.                      _loc14_ = _loc13_[_loc7_];
  126.                      if(param1.type == FlexEvent.SHOW && _loc14_.mx_internal::hideOnEffectEnd)
  127.                      {
  128.                         _loc14_.target.removeEventListener(FlexEvent.SHOW,_loc14_.mx_internal::eventHandler);
  129.                         _loc14_.mx_internal::hideOnEffectEnd = false;
  130.                      }
  131.                      _loc14_.end();
  132.                      _loc7_++;
  133.                   }
  134.                }
  135.                _loc5_++;
  136.             }
  137.          }
  138.          _loc3_.mx_internal::initEvent = param1;
  139.          _loc3_.addEventListener(EffectEvent.EFFECT_END,EffectManager.mx_internal::effectEndHandler);
  140.          mx_internal::lastEffectCreated = _loc3_;
  141.          _loc8_ = _loc3_.play();
  142.          _loc4_ = int(_loc8_.length);
  143.          _loc5_ = 0;
  144.          while(_loc5_ < _loc4_)
  145.          {
  146.             mx_internal::effectsPlaying.push(new EffectNode(_loc3_,_loc8_[_loc5_]));
  147.             _loc5_++;
  148.          }
  149.          if(_loc3_.suspendBackgroundProcessing)
  150.          {
  151.             UIComponent.suspendBackgroundProcessing();
  152.          }
  153.       }
  154.       
  155.       public static function suspendEventHandling() : void
  156.       {
  157.          ++eventHandlingSuspendCount;
  158.       }
  159.       
  160.       mx_internal static function registerEffectTrigger(param1:String, param2:String) : void
  161.       {
  162.          var _loc3_:Number = NaN;
  163.          if(param1 != "")
  164.          {
  165.             if(param2 == "")
  166.             {
  167.                _loc3_ = param1.length;
  168.                if(_loc3_ > 6 && param1.substring(_loc3_ - 6) == "Effect")
  169.                {
  170.                   param2 = param1.substring(0,_loc3_ - 6);
  171.                }
  172.             }
  173.             if(param2 != "")
  174.             {
  175.                effectTriggersForEvent[param2] = param1;
  176.                eventsForEffectTriggers[param1] = param2;
  177.             }
  178.          }
  179.       }
  180.       
  181.       private static function removedEffectHandler(param1:DisplayObject, param2:DisplayObjectContainer, param3:int, param4:Event) : void
  182.       {
  183.          suspendEventHandling();
  184.          param2.addChildAt(param1,param3);
  185.          resumeEventHandling();
  186.          createAndPlayEffect(param4,param1);
  187.       }
  188.       
  189.       mx_internal static function endVectorEffect(param1:IUIComponent) : void
  190.       {
  191.          cacheOrUncacheTargetAsBitmap(param1,false,false);
  192.       }
  193.       
  194.       public static function endEffectsForTarget(param1:IUIComponent) : void
  195.       {
  196.          var _loc2_:int = 0;
  197.          var _loc3_:int = 0;
  198.          var _loc4_:EffectInstance = null;
  199.          _loc2_ = int(mx_internal::effectsPlaying.length);
  200.          _loc3_ = _loc2_ - 1;
  201.          while(_loc3_ >= 0)
  202.          {
  203.             _loc4_ = mx_internal::effectsPlaying[_loc3_].instance;
  204.             if(_loc4_.target == param1)
  205.             {
  206.                _loc4_.end();
  207.             }
  208.             _loc3_--;
  209.          }
  210.       }
  211.       
  212.       private static function cacheOrUncacheTargetAsBitmap(param1:IUIComponent, param2:Boolean = true, param3:Boolean = true) : void
  213.       {
  214.          var _loc4_:int = 0;
  215.          var _loc5_:int = 0;
  216.          var _loc6_:Object = null;
  217.          _loc6_ = null;
  218.          _loc4_ = int(targetsInfo.length);
  219.          _loc5_ = 0;
  220.          while(_loc5_ < _loc4_)
  221.          {
  222.             if(targetsInfo[_loc5_].target == param1)
  223.             {
  224.                _loc6_ = targetsInfo[_loc5_];
  225.                break;
  226.             }
  227.             _loc5_++;
  228.          }
  229.          if(!_loc6_)
  230.          {
  231.             _loc6_ = {
  232.                "target":param1,
  233.                "bitmapEffectsCount":0,
  234.                "vectorEffectsCount":0
  235.             };
  236.             targetsInfo.push(_loc6_);
  237.          }
  238.          if(param2)
  239.          {
  240.             if(param3)
  241.             {
  242.                ++_loc6_.bitmapEffectsCount;
  243.                if(_loc6_.vectorEffectsCount == 0 && param1 is IDeferredInstantiationUIComponent)
  244.                {
  245.                   IDeferredInstantiationUIComponent(param1).cacheHeuristic = true;
  246.                }
  247.             }
  248.             else if(_loc6_.vectorEffectsCount++ == 0 && param1 is IDeferredInstantiationUIComponent && IDeferredInstantiationUIComponent(param1).cachePolicy == UIComponentCachePolicy.AUTO)
  249.             {
  250.                param1.cacheAsBitmap = false;
  251.             }
  252.          }
  253.          else
  254.          {
  255.             if(param3)
  256.             {
  257.                if(_loc6_.bitmapEffectsCount != 0)
  258.                {
  259.                   --_loc6_.bitmapEffectsCount;
  260.                }
  261.                if(param1 is IDeferredInstantiationUIComponent)
  262.                {
  263.                   IDeferredInstantiationUIComponent(param1).cacheHeuristic = false;
  264.                }
  265.             }
  266.             else if(_loc6_.vectorEffectsCount != 0)
  267.             {
  268.                if(--_loc6_.vectorEffectsCount == 0 && _loc6_.bitmapEffectsCount != 0)
  269.                {
  270.                   _loc4_ = int(_loc6_.bitmapEffectsCount);
  271.                   _loc5_ = 0;
  272.                   while(_loc5_ < _loc4_)
  273.                   {
  274.                      if(param1 is IDeferredInstantiationUIComponent)
  275.                      {
  276.                         IDeferredInstantiationUIComponent(param1).cacheHeuristic = true;
  277.                      }
  278.                      _loc5_++;
  279.                   }
  280.                }
  281.             }
  282.             if(_loc6_.bitmapEffectsCount == 0 && _loc6_.vectorEffectsCount == 0)
  283.             {
  284.                _loc4_ = int(targetsInfo.length);
  285.                _loc5_ = 0;
  286.                while(_loc5_ < _loc4_)
  287.                {
  288.                   if(targetsInfo[_loc5_].target == param1)
  289.                   {
  290.                      targetsInfo.splice(_loc5_,1);
  291.                      break;
  292.                   }
  293.                   _loc5_++;
  294.                }
  295.             }
  296.          }
  297.       }
  298.       
  299.       mx_internal static function eventHandler(param1:Event) : void
  300.       {
  301.          var _loc2_:FocusEvent = null;
  302.          var _loc3_:DisplayObject = null;
  303.          var _loc4_:int = 0;
  304.          var _loc5_:DisplayObjectContainer = null;
  305.          var _loc6_:int = 0;
  306.          if(!(param1.currentTarget is IFlexDisplayObject))
  307.          {
  308.             return;
  309.          }
  310.          if(eventHandlingSuspendCount > 0)
  311.          {
  312.             return;
  313.          }
  314.          if(param1 is FocusEvent && (param1.type == FocusEvent.FOCUS_OUT || param1.type == FocusEvent.FOCUS_IN))
  315.          {
  316.             _loc2_ = FocusEvent(param1);
  317.             if(Boolean(_loc2_.relatedObject) && (_loc2_.currentTarget.contains(_loc2_.relatedObject) || _loc2_.currentTarget == _loc2_.relatedObject))
  318.             {
  319.                return;
  320.             }
  321.          }
  322.          if((param1.type == Event.ADDED || param1.type == Event.REMOVED) && param1.target != param1.currentTarget)
  323.          {
  324.             return;
  325.          }
  326.          if(param1.type == Event.REMOVED)
  327.          {
  328.             if(param1.target is UIComponent)
  329.             {
  330.                if(UIComponent(param1.target).initialized == false)
  331.                {
  332.                   return;
  333.                }
  334.                if(UIComponent(param1.target).mx_internal::isEffectStarted)
  335.                {
  336.                   _loc4_ = 0;
  337.                   while(_loc4_ < UIComponent(param1.target).mx_internal::_effectsStarted.length)
  338.                   {
  339.                      if(UIComponent(param1.target).mx_internal::_effectsStarted[_loc4_].triggerEvent.type == Event.REMOVED)
  340.                      {
  341.                         return;
  342.                      }
  343.                      _loc4_++;
  344.                   }
  345.                }
  346.             }
  347.             _loc3_ = param1.target as DisplayObject;
  348.             if(_loc3_ != null)
  349.             {
  350.                _loc5_ = _loc3_.parent as DisplayObjectContainer;
  351.                if(_loc5_ != null)
  352.                {
  353.                   _loc6_ = _loc5_.getChildIndex(_loc3_);
  354.                   if(_loc6_ >= 0)
  355.                   {
  356.                      if(_loc3_ is UIComponent)
  357.                      {
  358.                         UIComponent(_loc3_).callLater(removedEffectHandler,[_loc3_,_loc5_,_loc6_,param1]);
  359.                      }
  360.                   }
  361.                }
  362.             }
  363.          }
  364.          else
  365.          {
  366.             createAndPlayEffect(param1,param1.currentTarget);
  367.          }
  368.       }
  369.       
  370.       mx_internal static function endBitmapEffect(param1:IUIComponent) : void
  371.       {
  372.          cacheOrUncacheTargetAsBitmap(param1,false,true);
  373.       }
  374.       
  375.       private static function animateSameProperty(param1:Effect, param2:Effect, param3:EffectInstance) : Boolean
  376.       {
  377.          var _loc4_:Array = null;
  378.          var _loc5_:Array = null;
  379.          var _loc6_:int = 0;
  380.          var _loc7_:int = 0;
  381.          var _loc8_:int = 0;
  382.          var _loc9_:int = 0;
  383.          if(param1.target == param3.target)
  384.          {
  385.             _loc4_ = param1.getAffectedProperties();
  386.             _loc5_ = param2.getAffectedProperties();
  387.             _loc6_ = int(_loc4_.length);
  388.             _loc7_ = int(_loc5_.length);
  389.             _loc8_ = 0;
  390.             while(_loc8_ < _loc6_)
  391.             {
  392.                _loc9_ = 0;
  393.                while(_loc9_ < _loc7_)
  394.                {
  395.                   if(_loc4_[_loc8_] == _loc5_[_loc9_])
  396.                   {
  397.                      return true;
  398.                   }
  399.                   _loc9_++;
  400.                }
  401.                _loc8_++;
  402.             }
  403.          }
  404.          return false;
  405.       }
  406.       
  407.       private static function loadResources() : void
  408.       {
  409.          resourceIncorrectTrigger = packageResources.getString("incorrectTrigger");
  410.       }
  411.       
  412.       mx_internal static function effectEndHandler(param1:EffectEvent) : void
  413.       {
  414.          var _loc2_:IEffectInstance = null;
  415.          var _loc3_:int = 0;
  416.          var _loc4_:int = 0;
  417.          var _loc5_:DisplayObject = null;
  418.          var _loc6_:DisplayObjectContainer = null;
  419.          _loc2_ = param1.effectInstance;
  420.          _loc3_ = int(mx_internal::effectsPlaying.length);
  421.          _loc4_ = _loc3_ - 1;
  422.          while(_loc4_ >= 0)
  423.          {
  424.             if(mx_internal::effectsPlaying[_loc4_].instance == _loc2_)
  425.             {
  426.                mx_internal::effectsPlaying.splice(_loc4_,1);
  427.                break;
  428.             }
  429.             _loc4_--;
  430.          }
  431.          if(Object(_loc2_).hideOnEffectEnd == true)
  432.          {
  433.             _loc2_.target.removeEventListener(FlexEvent.SHOW,Object(_loc2_).eventHandler);
  434.             _loc2_.target.setVisible(false,true);
  435.          }
  436.          if(Boolean(_loc2_.triggerEvent) && _loc2_.triggerEvent.type == Event.REMOVED)
  437.          {
  438.             _loc5_ = _loc2_.target as DisplayObject;
  439.             if(_loc5_ != null)
  440.             {
  441.                _loc6_ = _loc5_.parent as DisplayObjectContainer;
  442.                if(_loc6_ != null)
  443.                {
  444.                   suspendEventHandling();
  445.                   _loc6_.removeChild(_loc5_);
  446.                   resumeEventHandling();
  447.                }
  448.             }
  449.          }
  450.          if(_loc2_.suspendBackgroundProcessing)
  451.          {
  452.             UIComponent.resumeBackgroundProcessing();
  453.          }
  454.       }
  455.       
  456.       mx_internal static function startBitmapEffect(param1:IUIComponent) : void
  457.       {
  458.          cacheOrUncacheTargetAsBitmap(param1,true,true);
  459.       }
  460.       
  461.       mx_internal static function setStyle(param1:String, param2:*) : void
  462.       {
  463.          var _loc3_:String = null;
  464.          _loc3_ = eventsForEffectTriggers[param1];
  465.          if(_loc3_ != null && _loc3_ != "")
  466.          {
  467.             param2.addEventListener(_loc3_,EffectManager.mx_internal::eventHandler,false,EventPriority.EFFECT);
  468.          }
  469.       }
  470.       
  471.       mx_internal static function getEventForEffectTrigger(param1:String) : String
  472.       {
  473.          var effectTrigger:String = param1;
  474.          if(eventsForEffectTriggers)
  475.          {
  476.             try
  477.             {
  478.                return eventsForEffectTriggers[effectTrigger];
  479.             }
  480.             catch(e:Error)
  481.             {
  482.                return "";
  483.             }
  484.          }
  485.          else
  486.          {
  487.             return "";
  488.          }
  489.       }
  490.       
  491.       mx_internal static function createEffectForType(param1:Object, param2:String) : Effect
  492.       {
  493.          var trigger:String = null;
  494.          var value:Object = null;
  495.          var effectClass:Class = null;
  496.          var cls:Class = null;
  497.          var effectObj:Effect = null;
  498.          var doc:Object = null;
  499.          var target:Object = param1;
  500.          var type:String = param2;
  501.          trigger = effectTriggersForEvent[type];
  502.          if(trigger == "")
  503.          {
  504.             trigger = type + "Effect";
  505.          }
  506.          value = target.getStyle(trigger);
  507.          if(!value)
  508.          {
  509.             return null;
  510.          }
  511.          if(value is Class)
  512.          {
  513.             cls = Class(value);
  514.             return new cls(target);
  515.          }
  516.          try
  517.          {
  518.             if(value is String)
  519.             {
  520.                doc = target.parentDocument;
  521.                if(!doc)
  522.                {
  523.                   doc = Application.application;
  524.                }
  525.                effectObj = doc[value];
  526.             }
  527.             else if(value is Effect)
  528.             {
  529.                effectObj = Effect(value);
  530.             }
  531.             if(effectObj)
  532.             {
  533.                effectObj.target = target;
  534.                return effectObj;
  535.             }
  536.          }
  537.          catch(e:Error)
  538.          {
  539.          }
  540.          effectClass = Class(target.systemManager.getDefinitionByName("mx.effects." + value));
  541.          if(effectClass)
  542.          {
  543.             return new effectClass(target);
  544.          }
  545.          return null;
  546.       }
  547.       
  548.       public static function resumeEventHandling() : void
  549.       {
  550.          --eventHandlingSuspendCount;
  551.       }
  552.       
  553.       mx_internal static function startVectorEffect(param1:IUIComponent) : void
  554.       {
  555.          cacheOrUncacheTargetAsBitmap(param1,true,false);
  556.       }
  557.    }
  558. }
  559.  
  560. class EffectNode
  561. {
  562.    public var instance:EffectInstance;
  563.    
  564.    public var factory:Effect;
  565.    
  566.    public function EffectNode(param1:Effect, param2:EffectInstance)
  567.    {
  568.       super();
  569.       this.factory = param1;
  570.       this.instance = param2;
  571.    }
  572. }
  573.